<?php
session_start();
require_once "include/database.php";
$db = db_connect();
require_once "include/auth.php";
$current_user = current_user();
require_login();
require_user(0);
$title = "CS 4400 Project | Course Registration";
include "_header.php"; 

// Obtain Student Department ID.
$departmentquery = $db->prepare("SELECT department.Dept_ID AS id FROM regular_user
                                JOIN student ON regular_user.Username = student.Username
                                JOIN department ON department.Dept_Name = student.Major
                                WHERE regular_user.Username =  :username");
$departmentquery->execute(array("username" => $current_user['Username']));
$deptresult = $departmentquery->fetch();


// Perform the query to register for the course.
$mainquery = $db->prepare("SELECT * FROM SectionComplete WHERE Dept_ID = :deptid
                        AND Term = 'Fall 2012'");
$mainquery->execute(array("deptid" => $deptresult['id']));
echo "<div class='container'>";
echo "<form action='submitcourseselection.php' method='POST'>";
echo "<table class='table table-bordered table-hover'>";
echo "<h2 style='text-align:center;'> Register for Courses </h2>";
if ($_GET['error'] == 1) {
    echo "<h4 class='text-error' style='text-align:center;'> You must select at least one class! </h4>";
}
echo "<thead style='background-color:darkgrey'><tr>" .
    "<td>Select</td>" .
    "<td>CRN</td>" . 
    "<td>Course Code</td>" .
    "<td>Title</td>" . 
    "<td>Section</td>" . 
    "<td>Instructor</td>" . 
    "<td>Day</td>" . 
    "<td>Time</td>" . 
    "<td>Location</td>". 
    "<td>Grade Mode</td>" .
    "</tr></thead>";
while($mainresult = $mainquery->fetch()) {
    echo "<tr>";

    echo "<td>" . "<input type='checkbox' name='courses[]' value='" . $mainresult['CRN'] . "'></td>";

    echo "<td>" . $mainresult['CRN'] . "</td> <td>" .
    $mainresult['Code'] . "</td> <td>" .
    $mainresult['Title'] . "</td> <td>" .
    $mainresult['Section'] . "</td> <td>" .
    $mainresult['Instructor'] . "</td> <td>" .
    $mainresult['Day'] . "</td> <td>" .
    $mainresult['Time'] . "</td> <td>" .
    $mainresult['Location'] . "</td>";

    echo "<td><select name='g" . $mainresult['CRN'] . "'><option value='Registered'>Register</option><option value='Audit'>" .
         "Audit</option><option value='Pass/Fail'>Pass / Fail</option>";

    echo "</tr>";
}
echo "</tbody></table>";

echo "<input type='submit' class='pull-right'>";
echo "</form>";
echo "</div>";
?>
<?php include "_footer.php";?>